<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="导入日期" prop="importDate">
        <el-date-picker clearable v-model="queryParams.importDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00" placeholder="请选择导入日期">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="员工编号" prop="partyId">
        <el-input v-model="queryParams.partyId" placeholder="请输入员工编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="姓名" prop="firstName">
        <el-input v-model="queryParams.firstName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机" prop="mobilePhone">
        <el-input v-model="queryParams.mobilePhone" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证" prop="cardId">
        <el-input v-model="queryParams.cardId" placeholder="请输入身份证号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="导入状态" prop="importStatusId">
        <el-select v-model="queryParams.importStatusId" placeholder="请选择导入状态" clearable>
          <el-option v-for="dict in importStatusIdOptions" :key="dict.enumCode" :label="dict.description"
            :value="dict.enumCode" />
        </el-select>
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <el-select v-model="queryParams.deptId" placeholder="请选择入职部门" clearable filterable>
          <el-option v-for="dict in deptIdOptions" :key="dict.deptId" :label="dict.deptName" :value="dict.deptId" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['ehr:employeeImportRecord:add']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['ehr:employeeImportRecord:edit']">修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['ehr:employeeImportRecord:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['ehr:employeeImportRecord:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['ehr:employeeImportRecord:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeeImportRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录编号" align="center" prop="importId" />
      <el-table-column label="导入日期" align="center" prop="importDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.importDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="导入状态" align="center" prop="importStatusId" width="80" :formatter="importStatusIdFormat" />
      <el-table-column label="员工编号" align="center" prop="partyId" />
      <el-table-column label="姓名" align="center" prop="firstName" width="100" :formatter="firstNameFormat" />
      <el-table-column label="性别" align="center" prop="gender" width="60" :formatter="genderFormat" />
      <el-table-column label="民族" align="center" prop="nation" width="60" :formatter="nationFormat" />
      <el-table-column label="出生日期" align="center" prop="birthDate" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="证件类型" align="center" prop="cardType" width="80" :formatter="cardTypeFormat" />
      <el-table-column label="证件号码" align="center" prop="cardId" width="120" />
      <!-- <el-table-column label="证件到期日期" align="center" prop="cardDueDate" width="100"/> -->
      <!-- <el-table-column label="现居住地" align="center" prop="residentialAddress" width="120"  /> -->
      <el-table-column label="手机号" align="center" prop="mobilePhone" width="100" />
      <el-table-column label="个人邮箱" align="center" prop="personalEmail" width="100" />
      <!-- <el-table-column label="入职类别" align="center" prop="entryType" width="100" :formatter="entryTypeFormat" /> -->
      <el-table-column label="员工类型" align="center" prop="emplType" width="100" :formatter="emplTypeFormat" />
      <!-- <el-table-column label="入职公司" align="center" prop="orgId" /> -->
      <el-table-column label="入职部门" align="center" prop="deptId" width="100" :formatter="deptIdFormat" />
      <el-table-column label="入职岗位" align="center" prop="positionId" width="100" :formatter="positionIdFormat" />
      <el-table-column label="入职日期" align="center" prop="entryDate" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上级主管" align="center" prop="supervisor" width="100" :formatter="supervisorFormat" />
      <el-table-column label="学历" align="center" prop="education" width="80" :formatter="educationFormat" />
      <!-- <el-table-column label="首次参加工作日期" align="center" prop="joinWorkTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinWorkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="更新时间" align="center" prop="lastUpdatedStamp" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdatedStamp, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="handleDetail(scope.row)"
            v-hasPermi="['ehr:employeeImportRecord:detail']">详情</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['ehr:employeeImportRecord:edit']">修改</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['ehr:employeeImportRecord:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改员工数据导入对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" v-bind:disabled=detailFlag>
        <el-row>
          <el-col :span="12">
            <el-form-item label="导入日期" prop="importDate">
              <el-date-picker clearable v-model="form.importDate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                default-time="00:00:00" placeholder="请选择导入日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工编号" prop="partyId">
              <el-input v-model="form.partyId" placeholder="请输入员工编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="firstName">
              <el-select v-model="form.firstName" placeholder="请选择姓名" filterable>
                <el-option v-for="dict in firstNameOptions" :key="dict.partyId" :label="dict.firstName"
                  :value="dict.partyId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-select v-model="form.gender" placeholder="请选择性别">
                <el-option v-for="dict in genderOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-select v-model="form.nation" placeholder="请选择民族">
                <el-option v-for="dict in nationOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期" prop="birthDate">
              <el-date-picker clearable v-model="form.birthDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择出生日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="证件类型" prop="cardType">
              <el-select v-model="form.cardType" placeholder="请选择证件类型">
                <el-option v-for="dict in cardTypeOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码" prop="cardId">
              <el-input v-model="form.cardId" placeholder="请输入证件号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="证件到期日期" prop="cardDueDate">
              <el-input v-model="form.cardDueDate" placeholder="请输入证件到期日期" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="现居住地" prop="residentialAddress">
              <el-input v-model="form.residentialAddress" placeholder="请输入现居住地" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号" prop="mobilePhone">
              <el-input v-model="form.mobilePhone" placeholder="请输入手机号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="个人邮箱" prop="personalEmail">
              <el-input v-model="form.personalEmail" placeholder="请输入个人邮箱" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="入职类别" prop="entryType">
              <el-select v-model="form.entryType" placeholder="请选择入职类别">
                <el-option v-for="dict in entryTypeOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="员工类型" prop="emplType">
              <el-select v-model="form.emplType" placeholder="请选择员工类型">
                <el-option v-for="dict in emplTypeOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="入职部门" prop="deptId">
              <el-select v-model="form.deptId" placeholder="请选择入职部门" filterable>
                <el-option v-for="dict in deptIdOptions" :key="dict.deptId" :label="dict.deptName"
                  :value="dict.deptId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入职岗位" prop="positionId">
              <el-select v-model="form.positionId" placeholder="请选择入职岗位" filterable>
                <el-option v-for="dict in positionIdOptions" :key="dict.postId" :label="dict.postName"
                  :value="dict.postId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="上级主管" prop="supervisor">
              <el-select v-model="form.supervisor" placeholder="请选择上级主管" filterable>
                <el-option v-for="dict in supervisorOptions" :key="dict.partyId" :label="dict.firstName"
                  :value="dict.partyId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入职日期" prop="entryDate">
              <el-date-picker clearable v-model="form.entryDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择入职日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学历" prop="education">
              <el-select v-model="form.education" placeholder="请选择学历">
                <el-option v-for="dict in educationOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="首次参加工作日期" prop="joinWorkTime">
              <el-date-picker clearable v-model="form.joinWorkTime" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择首次参加工作日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="导入状态" prop="importStatusId">
              <el-select v-model="form.importStatusId" placeholder="请选择导入状态">
                <el-option v-for="dict in importStatusIdOptions" :key="dict.enumCode" :label="dict.description"
                  :value="dict.enumCode"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="editFlag" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 员工数据导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!-- <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" />
            是否更新已经存在的员工数据
          </div> -->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { listEmployeeImportRecord, getEmployeeImportRecord, delEmployeeImportRecord, addEmployeeImportRecord, updateEmployeeImportRecord } from "@/api/ehr/employeeImportRecord";

export default {
  name: "EmployeeImportRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工数据导入表格数据
      employeeImportRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 导入状态业务字典
      importStatusIdOptions: [],
      // 姓名业务字典
      firstNameOptions: [],
      // 性别业务字典
      genderOptions: [],
      // 民族业务字典
      nationOptions: [],
      // 证件类型业务字典
      cardTypeOptions: [],
      // 入职类别业务字典
      entryTypeOptions: [],
      // 员工类型业务字典
      emplTypeOptions: [],
      // 入职公司业务字典
      orgIdOptions: [],
      // 入职部门业务字典
      deptIdOptions: [],
      // 入职岗位业务字典
      positionIdOptions: [],
      // 上级主管业务字典
      supervisorOptions: [],
      // 学历（最高）业务字典
      educationOptions: [],
      // 操作标识,用于区分是新增还是修改
      updateFlag: false,
      // 操作标识,用于区分是详情
      detailFlag: false,
      // 操作标识,用于区分编辑状态
      editFlag: false,

      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/ehr/employeeImportRecord/importData",
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "", // 排序字段
        isAsc: "", // 升序或降序 大写的 ASC或DESC,为空代表升序
        importDate: null,
        importStatusId: null,
        partyId: null,
        firstName: null,
        cardId: null,
        mobilePhone: null,
        orgId: null,
        deptId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    // 导入状态业务字典
    this.getEnumDicts("EMPL_IMPORT_STATUS").then((response) => {
      this.importStatusIdOptions = response.data;
    });
    // 姓名业务字典
    this.getEntityDicts("person:partyId:firstName").then((response) => {
      this.firstNameOptions = response.data;
    });
    // 性别业务字典
    this.getEnumDicts("PERSON_GENDER").then((response) => {
      this.genderOptions = response.data;
    });
    // 民族业务字典
    this.getEnumDicts("PERSON_NATION").then((response) => {
      this.nationOptions = response.data;
    });
    // 证件类型业务字典
    this.getEnumDicts("PERSON_CARD_TYPE").then((response) => {
      this.cardTypeOptions = response.data;
    });
    // 入职类别业务字典
    this.getEnumDicts("EMPL_ENTRY_TYPE").then((response) => {
      this.entryTypeOptions = response.data;
    });
    // 员工类型业务字典
    this.getEnumDicts("EMPL_TYPE").then((response) => {
      this.emplTypeOptions = response.data;
    });
    // 入职部门业务字典
    this.getEntityDicts("SysDept:deptId:deptName").then((response) => {
      this.deptIdOptions = response.data;
    });
    // 入职岗位业务字典
    this.getEntityDicts("SysPost:postId:postName").then((response) => {
      this.positionIdOptions = response.data;
    });
    // 上级主管业务字典
    this.getEntityDicts("person:partyId:firstName").then((response) => {
      this.supervisorOptions = response.data;
    });
    // 学历（最高）业务字典
    this.getEnumDicts("PERSON_EDUCATION").then((response) => {
      this.educationOptions = response.data;
    });
    this.getList();
  },
  methods: {
    importStatusIdFormat(row, column) {
      let val = null;
      this.importStatusIdOptions.forEach((item, index) => {
        if (row.importStatusId === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    firstNameFormat(row, column) {
      let val = null;
      this.firstNameOptions.forEach((item, index) => {
        if (row.firstName === item.partyId) {
          val = item.firstName;
        }
      });
      return val;
    },
    genderFormat(row, column) {
      let val = null;
      this.genderOptions.forEach((item, index) => {
        if (row.gender === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    nationFormat(row, column) {
      let val = null;
      this.nationOptions.forEach((item, index) => {
        if (row.nation === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    cardTypeFormat(row, column) {
      let val = null;
      this.cardTypeOptions.forEach((item, index) => {
        if (row.cardType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    entryTypeFormat(row, column) {
      let val = null;
      this.entryTypeOptions.forEach((item, index) => {
        if (row.entryType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    emplTypeFormat(row, column) {
      let val = null;
      this.emplTypeOptions.forEach((item, index) => {
        if (row.emplType === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    deptIdFormat(row, column) {
      let val = null;
      this.deptIdOptions.forEach((item, index) => {
        if (row.deptId === item.deptId + "") {
          val = item.deptName;
        }
      });
      return val;
    },
    positionIdFormat(row, column) {
      let val = null;
      this.positionIdOptions.forEach((item, index) => {
        if (row.positionId === item.postId + "") {
          val = item.postName;
        }
      });
      return val;
    },
    supervisorFormat(row, column) {
      let val = null;
      this.supervisorOptions.forEach((item, index) => {
        if (row.supervisor === item.partyId) {
          val = item.firstName;
        }
      });
      return val;
    },
    educationFormat(row, column) {
      let val = null;
      this.educationOptions.forEach((item, index) => {
        if (row.education === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    /** 查询员工数据导入列表 */
    getList() {
      this.loading = true;
      listEmployeeImportRecord(this.queryParams).then(response => {
        this.employeeImportRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        importId: null,
        importDate: null,
        importStatusId: null,
        partyId: null,
        firstName: null,
        gender: null,
        nation: null,
        birthDate: null,
        cardType: null,
        cardId: null,
        cardDueDate: null,
        residentialAddress: null,
        mobilePhone: null,
        personalEmail: null,
        entryType: null,
        emplType: null,
        orgId: null,
        deptId: null,
        positionId: null,
        entryDate: null,
        supervisor: null,
        education: null,
        joinWorkTime: null,
        lastUpdatedStamp: null,
        lastUpdatedTxStamp: null,
        createdStamp: null,
        createdTxStamp: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.importId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.editFlag = true,
        this.updateFlag = false;
      this.detailFlag = false;
      this.reset();
      this.open = true;
      this.title = "添加员工数据导入";
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.editFlag = false,
        this.updateFlag = false;
      this.detailFlag = true;
      this.reset();
      const importId = row.importId || this.ids
      getEmployeeImportRecord(importId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "员工数据导入详情";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.editFlag = true;
      this.updateFlag = true;
      this.detailFlag = false;
      this.reset();
      const importId = row.importId || this.ids
      getEmployeeImportRecord(importId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改员工数据导入";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.importId != null && this.updateFlag) {
            updateEmployeeImportRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEmployeeImportRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const importIds = row.importId || this.ids;
      this.$modal.confirm('是否确认删除员工数据导入编号为"' + importIds + '"的数据项？').then(function () {
        return delEmployeeImportRecord(importIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ehr/employeeImportRecord/export', {
        ...this.queryParams
      }, `employeeImportRecord_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "员工数据导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "ehr/employeeImportRecord/importTemplate",
        {},
        // `person_template_${new Date().getTime()}.xlsx`
        `员工数据导入模版_${new Date().getTime()}.xlsx`
      );
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      if (response.code == 200) {
        response.msg = "导入成功！"
      }
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg +
        "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
  }
};
</script>
